package nwpu.lizhiwen.system;


import java.util.Scanner;


//该类与acticitysystem类方法逻辑均相同，故只在acticitysystem类进行注释，这里不再注释
public class UserSystem {
    private User users[];
    private int userNumber = 3;
    private Team teams[] = new Team[20];
    private int teamNumber = 0;
    Scanner scanner = new Scanner(System.in);

    public UserSystem(int size) {
        users = new User[size];
        users[0] = new Student("1", "李", "18712192278", "lzw.6868@qq.com", "2022302764", "男", "大二", "软件");
        users[1] = new Teacher("stu_002", "肖老师", "15304114352", "xiao@nwpu.edu.cn", "01342", "软件");
        users[2] = new Organizer("stu_003", "软件学院官方", "010" + "-03901234", "software@nwpu.edu.cn", "软件学院");
    }

    public User[] show(){
        return users;
    }

    public boolean add(User user){
        if (userNumber == users.length){
            System.out.println("数组已满，不可再添加");
            return false;
        }
        users[userNumber++] = user;
        return true;
    }

    public boolean del(String delId){
        int index = -1;
        for (int i = 0;i <userNumber; i++){
            if (delId .equals(users[i].getId()) ){
                index = i;
            }
        }
        if (index == -1){
            return false;
        }
        for (int i = index; i < userNumber-1; i++){
            users[i] = users[i+1];
        }
        users[userNumber-1] = null;
        userNumber--;
        return true;
    }

    public User find(String findId){
        for (int i = 0; i < userNumber; i++){
            if (findId.equals(users[i].getId()) ){
                return users[i];
            }
        }
        return null;
    }

    public Team findTeam(String teamId){
        for (int i = 0; i < teamNumber; i++){
            if (teamId.equals(teams[i].getTeamId()) ){
                return teams[i];
            }
        }
        return null;
    }

    public void create(String craetorId ,String teamId,String teamName, String department ){
        //先找到创建者
        Student student = (Student) find(craetorId) ;
        if (student == null){
            System.out.println("该学生不存在");
            return;
        }
        //构造器传入team的信息
        teams[teamNumber++]  = new Team(teamId,teamName,department,student);
        System.out.println("创建成功");
    }
}
